package design.mode.effective_java.chapter2.item8;/*
package com.rootnet.learn.design_patterns.effective_java.chapter2.item8;

import sun.misc.Cleaner;

*/
/**
 * 假设房间在回收之前必须被清理
 *
 * @author ZhongMingde on 2021/8/5
 *//*


public class Room implements AutoCloseable  {
    private static final Cleaner cleaner  = Cleaner.create();

    private final State state;

    private final Cleaner.Cleanable cleanable;
    public Room(int numJunkPiles) {
        state = new State(numJunkPiles);
        cleanable = cleaner.register(this, state);
    }

    @Override
    public void close()  {
        cleanable.clean();
    }



    private static class State implements Runnable {
        int numJunkPiles;

        State(int numJunkPiles) {
            this.numJunkPiles = numJunkPiles;
        }

        @Override
        public void run() {
            System.out.println("Cleaning Room");
            numJunkPiles = 0;
        }
    }


}
*/
